package fatworm.query;

import fatworm.query.constant.Constant;

public class SortScan implements Scan {
	
	private Scan s;
	private TupleList list;
	private int index;
	
	public SortScan(Scan s, String name, boolean flag) {
		this.s = s;
		//TODO
		list = new TupleList(null);
		
		s.beforeFirst();
		while (s.next()) 
			list.add(s);
		
		list.sort(flag, name);
	}
	public void beforeFirst() {
		index = -1;
	}
	
	public boolean next() {
		index++;
		return index < list.getSize();
	}
	
	public void close() {
		s.close();
	}
	
	public Constant getVal(String name) {
		return list.getVal(index, name);
	}
	
	public int getInt(String name) {
		return list.getInt(index, name);
	}
	
	public String getString(String name) {
		return list.getString(index, name);
	}
	
	public boolean hasField(String name) {
		return s.hasField(name);
	}
}